<template>
	<view class="ys">
		<view class="form">
			<uni-section title="房间号" type="line">
				<view class="inputbox">
					<uni-easyinput v-model="name" trim placeholder="请输入房间号" clearSize="20"></uni-easyinput>
				</view>
			</uni-section>
		</view>

		<button class="btn" @click="addRoom" :loading="loading" :disabled="loading">提交</button>
	</view>
</template>

<script>
	import {
		addRoom
	} from "@/api/user.js"
	export default {
		data() {
			return {
				name: '',
				loading: false
			}
		},
		onLoad() {

		},
		methods: {

			addRoom() {
				let that = this
				if (this.name == '') {
					return uni.$showMsg('请输入房间号')
				}
				that.loading = true
				addRoom({
					name: this.name,
				}).then(res => {
					uni.$showMsg(res.msg)
					if (res.code == 0) {
						setTimeout(() => {
							uni.navigateBack()
						}, 1000)
					} else {
						that.loading = false
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.ys {
		.inputbox {
			width: 96%;
			margin: 0px auto;
		}

		.form {
			padding-bottom: 15px;
			background: #fff;
		}

		.btn {
			button {
				color: #fff;
				font-size: 16px;
				letter-spacing: 1px;
				margin: 30px auto;
				width: 96%;
			}
		}
	}
</style>